package com.alageek.study.dao;

import com.alageek.study.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;

import java.util.List;

/**
 * path修改请求路径
 * collectionResourceRel修改返回JSON集合中book集合的key
 * itemResourceRel修改返回JSON集合中单个book的key
 */
@RepositoryRestResource(path = "bs", collectionResourceRel = "bs", itemResourceRel = "b", exported = true)
public interface BookRepository extends JpaRepository<Book, Integer> {

    /**
     * 默认请求路径为/bs/search/findByAuthorContains?author=鲁迅
     * 添加注解后的请求路径为/bs/search/author?author=鲁迅
     * @param author
     * @return
     */
    @RestResource(path = "author", rel = "author")
    List<Book> findByAuthorContains(@Param("author") String author);

    @RestResource(path = "name", rel = "name")
    Book findByNameEquals(@Param("name") String name);

    @Override
    @RestResource(exported = false)
    void deleteById(Integer integer);
}
